package serial_cli

import (
	"fmt"
	"github.com/spf13/cobra"
	"go.bug.st/serial"
	"log"
)

func PortsCmd() *cobra.Command {

	cmd := &cobra.Command{
		Use:   "ports",
		Short: "查看当前系统的串口",
		Long:  `查看当前系统的串口`,
		Run: func(cmd *cobra.Command, args []string) {
			ports, err := serial.GetPortsList()
			if err != nil {
				log.Fatal(err)
				return
			}
			if len(ports) == 0 {
				log.Fatal("No serial ports found!")
				return
			}
			for _, port := range ports {
				fmt.Printf("Found port: %v\n", port)
			}
		},
	}
	return cmd
}
